/*
 * (C) 2012	Sheng Yi
 * Test if file can use lseek normally when is opend with append flag
 * Results show that data is always wrote to file end when use flag O_APPEND 
 */
#include "apue.h"
#include "fcntl.h"

int main()
{
	int n, fd, len;
	char *buf = "This in begin?";
	char *buf2 = "This in end.";

	if ((fd = open("dump.file", O_RDWR | O_APPEND)) < 0)
		err_quit("open error");

	/* now seek first, then write */
	if ((n = lseek(fd, 0, SEEK_SET)) == -1)
		err_quit("lseek error");

	len = strlen(buf);
	if ((n = write(fd, buf, len)) != len)
		err_quit("write error");

	len = strlen(buf2);
	if ((n = write(fd, buf2, len)) != len)
		err_quit("write error");

	close(fd);

	return 0;
}
